'''
Created on Feb 28, 2012

@author: poncho

Here are some tests that I made to understand how does the schedule work.
During my trip I will try to understand all the updates and with that make the things that you need.

'''

from apscheduler.scheduler import Scheduler
import datetime
import signal
import time

def job_function1():
    print "Test 1"
    print datetime.datetime.now()
    
def job_function2():
    print "Test 2"
    print datetime.datetime.now()
    
def job_function3():
    print "Test 3"
    print datetime.datetime.now()

def init_schedule():
    # Declare the variable
    sched = Scheduler()
    # Start the scheduler
    sched.start()

    return sched

def schedule_job(sched, function, periodicity, start_time):
     #add_cron_job(func, year=None, month=None, day=None, week=None, day_of_week=None, hour=None, minute=None, 
     #second=None, start_date=None, args=None, kwargs=None, **options)
    sched.add_cron_job(function, second = periodicity, start_date = start_time)

def print_time(sched):
    jobs = list(sched.get_jobs())
    for i in range(0 , 3):
        z = str(jobs[i])
        print "The next run of the jobs "+ str(i) +" is " + z[52:75]
        
    
    
#def printDate(sched, function):

if __name__ == "__main__":

    print datetime.datetime.now()
    sched0 = init_schedule()
    sched1 = init_schedule()
    schedule_job(sched0, job_function1, 10, datetime.datetime.now())
    schedule_job(sched0, job_function2, 15, datetime.datetime.now())
    schedule_job(sched0, job_function3, 20, datetime.datetime.now())
    while(sched0.running):
        print_time(sched0)
        time.sleep(50)
    
    
   # sched.print_jobs() @IndentOk
    

#    sched.cron_schedule()
#    sched.get_jobs()
#   if sched.running():
#        print "Working"
#    else:
#        print "Not working" 
    
    signal.pause()
    